package com.uniinnovate.lanjingling.service.impl;

import com.uniinnovate.lanjingling.pojo.vo.UserInfoVO;
import com.uniinnovate.lanjingling.utils.R;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uniinnovate.lanjingling.utils.PageUtils;
import com.uniinnovate.lanjingling.utils.Query;

import com.uniinnovate.lanjingling.dao.UserDao;
import com.uniinnovate.lanjingling.entity.UserEntity;
import com.uniinnovate.lanjingling.service.UserService;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserEntity> page = this.page(
                new Query<UserEntity>().getPage(params),
                new QueryWrapper<UserEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R perfectInfo(UserInfoVO userInfoVO) {
        UserEntity user = getById(userInfoVO.getUserId());
        BeanUtils.copyProperties(userInfoVO,user);
        boolean update = updateById(user);
        if(update){
            return R.ok("个人信息完善成功");
        }else{
            return R.error("个人信息完善失败");
        }
    }

}